package view.swing.popup;

import static util.Strings.STR_GAME_ENDED;
import static util.Strings.STR_RANKING;
import static util.Strings.STR_RANKING_LINE;

import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

import model.iview.IPlayer;
import model.iview.ScoreComparator;
public class EndGameWindow {

	private List<IPlayer> players;

	private EndGameWindow() {

	}

	public EndGameWindow(List<IPlayer> list) {
		this();
		this.players = list;
	}

	public void showWindow() {
		StringBuffer sb = new StringBuffer();
		sb.append(STR_GAME_ENDED);
		sb.append("\n\n");
		sb.append(STR_RANKING);
		sb.append("\n");
		Collections.sort(players, new ScoreComparator());
		for (int i = 0; i < players.size(); i++) {
			sb.append(String.format(STR_RANKING_LINE, (i + 1), players.get(i).getName(), players.get(i).getScore()));
			sb.append("\n");
		}
		JOptionPane.showMessageDialog(null, sb.toString(), "Partie terminée",
				JOptionPane.INFORMATION_MESSAGE);
	}
}
